import 'package:flutter_massage/common_lib/index.dart';
import 'package:flutter_massage/pages/my/address/address_bean.dart';
import 'package:flutter_massage/pages/technician/choose_address/edit_address_page.dart';
import 'package:flutter_massage/sqlite/db_manager.dart';
import 'package:get/get.dart';

class MyAddressLogic extends GetxController {
  List<AddressBean> list = [];
  @override
  void onReady() {
    super.onReady();
    CommonObservable().addObserver(EditAddressLogic.keyListener, refreshList);
    getAddressList();
  }

  @override
  void onClose() {
    super.onClose();
    CommonObservable().removeObserver(EditAddressLogic.keyListener, refreshList);
  }

  void refreshList(key, [value]) => getAddressList();

  void getAddressList() async {
    list = await DbManager.getAddressList();
    update();
  }

  void deleteAddress(AddressBean bean) async {
    if (bean.addressId.empty) return;
    await DbManager.deleteAddress(bean.addressId!);
    getAddressList();
  }
}
